package cn.anc.aonicardv.module.ui.base;

import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by yangdai on 2017/5/16.
 */

public abstract class BaseFragment extends Fragment {

    private Unbinder unbinder;

    protected View initView(int res) {
        View view = LayoutInflater.from(getContext()).inflate(res, null);
        findViewById(view);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    protected void initButterKnife(Object target,View view) {
        unbinder = ButterKnife.bind(target, view);
    }


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initVariable();
        setListener();
        initData();
    }


    public abstract void initVariable();

    public abstract void findViewById(View view);

    public abstract void setListener();

    public abstract void initData();


    @Override
    public void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
    }


    public boolean onKeyDown(int keyCode, KeyEvent event) {

        return false;
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        getActivity().onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

}
